package com.ey12.db.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ey12.db.domain.GmConfig;

/**
 * Data access object (DAO) for domain model class GmConfig.
 * 
 * @see com.ey12.db.domain.GmConfig
 * @author MyEclipse Persistence Tools
 */

public class GmConfigDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(GmConfigDAO.class);
	// property constants
	public static final String CONTENT = "content";
	public static final String URL = "url";
	public static final String IMANGE_PATH = "imagePath";
	public static final String AD_TYPE = "adType";

	protected void initDao() {
		// do nothing
	}

	public void saveOrUpdate(GmConfig transientInstance) {
		log.debug("saving GmConfig instance");
		try {
			getHibernateTemplate().saveOrUpdate(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			re.printStackTrace();
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(GmConfig persistentInstance) {
		log.debug("deleting GmConfig instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			re.printStackTrace();
			log.error("delete failed", re);
			throw re;
		}
	}

	public GmConfig findById(java.lang.Integer id) {
		log.debug("getting GmConfig instance with id: " + id);
		try {
			GmConfig instance = (GmConfig) getHibernateTemplate().get(
					"com.ey12.db.domain.GmConfig", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(GmConfig instance) {
		log.debug("finding GmConfig instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding GmConfig instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from GmConfig as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			re.printStackTrace();
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByContent(Object content) {
		return findByProperty(CONTENT, content);
	}

	public List findByUrl(Object url) {
		return findByProperty(URL, url);
	}

	public List findByImangePath(Object imangePath) {
		return findByProperty(IMANGE_PATH, imangePath);
	}

	public List findByAdType(Object adType) {
		return findByProperty(AD_TYPE, adType);
	}

	public List findAll() {
		log.debug("finding all GmConfig instances");
		try {
			String queryString = "from GmConfig";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			re.printStackTrace();
			log.error("find all failed", re);
			throw re;
		}
	}

	public GmConfig merge(GmConfig detachedInstance) {
		log.debug("merging GmConfig instance");
		try {
			GmConfig result = (GmConfig) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(GmConfig instance) {
		log.debug("attaching dirty GmConfig instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(GmConfig instance) {
		log.debug("attaching clean GmConfig instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static GmConfigDAO getFromApplicationContext(ApplicationContext ctx) {
		return (GmConfigDAO) ctx.getBean("GmConfigDAO");
	}
}